home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / OptionsAdminInterfacePage.cpp < prev    next >
C/C++ Source or Header  |  2011-11-06  |  7KB  |  238 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // OptionsAdminInterfacePage.cpp: Implementierungsdatei
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "filezilla server.h"
  24. #include "OptionsDlg.h"
  25. #include "OptionsPage.h"
  26. #include "OptionsAdminInterfacePage.h"
  27. #include "../iputils.h"
  28.  
  29. #if defined(_DEBUG) && !defined(MMGR)
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Dialogfeld COptionsAdminInterfacePage 
  37.  
  38.  
  39. COptionsAdminInterfacePage::COptionsAdminInterfacePage(COptionsDlg *pOptionsDlg, CWnd* pParent /*=NULL*/)
  40.     : COptionsPage(pOptionsDlg, COptionsAdminInterfacePage::IDD, pParent)
  41. {
  42.     //{{AFX_DATA_INIT(COptionsAdminInterfacePage)
  43.     m_Port = _T("");
  44.     m_IpAddresses = _T("");
  45.     m_IpBindings = _T("");
  46.     m_NewPass = _T("");
  47.     m_NewPass2 = _T("");
  48.     m_bChangePass = FALSE;
  49.     //}}AFX_DATA_INIT
  50. }
  51.  
  52.  
  53. void COptionsAdminInterfacePage::DoDataExchange(CDataExchange* pDX)
  54. {
  55.     COptionsPage::DoDataExchange(pDX);
  56.     //{{AFX_DATA_MAP(COptionsAdminInterfacePage)
  57.     DDX_Control(pDX, IDC_OPTIONS_ADMININTERFACE_CHANGEPASS, m_cChangePass);
  58.     DDX_Control(pDX, IDC_OPTIONS_ADMININTERFACE_NEWPASS2, m_cNewPass2);
  59.     DDX_Control(pDX, IDC_OPTIONS_ADMININTERFACE_NEWPASS, m_cNewPass);
  60.     DDX_Text(pDX, IDC_OPTIONS_ADMININTERFACE_PORT, m_Port);
  61.     DDV_MaxChars(pDX, m_Port, 5);
  62.     DDX_Text(pDX, IDC_OPTIONS_ADMININTERFACE_IPADDRESSES, m_IpAddresses);
  63.     DDX_Text(pDX, IDC_OPTIONS_ADMININTERFACE_IPBINDINGS, m_IpBindings);
  64.     DDX_Text(pDX, IDC_OPTIONS_ADMININTERFACE_NEWPASS, m_NewPass);
  65.     DDX_Text(pDX, IDC_OPTIONS_ADMININTERFACE_NEWPASS2, m_NewPass2);
  66.     DDX_Check(pDX, IDC_OPTIONS_ADMININTERFACE_CHANGEPASS, m_bChangePass);
  67.     //}}AFX_DATA_MAP
  68. }
  69.  
  70.  
  71. BEGIN_MESSAGE_MAP(COptionsAdminInterfacePage, COptionsPage)
  72.     //{{AFX_MSG_MAP(COptionsAdminInterfacePage)
  73.     ON_BN_CLICKED(IDC_OPTIONS_ADMININTERFACE_CHANGEPASS, OnOptionsAdmininterfaceChangepass)
  74.     //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // Behandlungsroutinen fⁿr Nachrichten COptionsAdminInterfacePage 
  79.  
  80. void COptionsAdminInterfacePage::OnOptionsAdmininterfaceChangepass() 
  81. {
  82.     UpdateData(TRUE);
  83.  
  84.     m_cNewPass.EnableWindow(m_bChangePass);
  85.     m_cNewPass2.EnableWindow(m_bChangePass);    
  86. }
  87.  
  88. BOOL COptionsAdminInterfacePage::OnInitDialog() 
  89. {
  90.     COptionsPage::OnInitDialog();
  91.     
  92.     if (m_NewPass != _T(""))
  93.     {
  94.         m_NewPass = _T("");
  95.         m_bChangePass = TRUE;
  96.         UpdateData(FALSE);
  97.  
  98.         m_cChangePass.EnableWindow(FALSE);
  99.     }
  100.     m_cNewPass.EnableWindow(m_bChangePass);
  101.     m_cNewPass2.EnableWindow(m_bChangePass);
  102.     
  103.     return TRUE;  // return TRUE unless you set the focus to a control
  104.                   // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurⁿckgeben
  105. }
  106.  
  107. BOOL COptionsAdminInterfacePage::IsDataValid()
  108. {
  109.     USES_CONVERSION;
  110.  
  111.     if (!UpdateData(TRUE))
  112.         return FALSE;
  113.  
  114.     if (_ttoi(m_Port) < 1 || _ttoi(m_Port) > 65535)
  115.     {
  116.         m_pOptionsDlg->ShowPage(this);
  117.         GetDlgItem(IDC_OPTIONS_ADMININTERFACE_PORT)->SetFocus();
  118.         AfxMessageBox(_T("The port for the admin interface has to be in the range from 1 to 65535."));
  119.         return FALSE;
  120.     }
  121.  
  122.     CString bindIPs = m_IpBindings;
  123.     CString sub;
  124.     std::list<CString> ipBindList;
  125.     for (int i = 0; i<bindIPs.GetLength(); i++)
  126.     {
  127.         TCHAR cur = bindIPs[i];
  128.         if ((cur < '0' || cur > '9') && cur != '.')
  129.         {
  130.             if (sub == _T("") && cur == '*')
  131.             {
  132.                 ipBindList.clear();
  133.                 ipBindList.push_back(_T("*"));
  134.                 break;
  135.             }
  136.  
  137.             if (sub != _T(""))
  138.             {
  139.                 //Parse IP
  140.                 SOCKADDR_IN sockAddr;
  141.                 memset(&sockAddr,0, sizeof(sockAddr));
  142.             
  143.                 sockAddr.sin_family = AF_INET;
  144.                 sockAddr.sin_addr.s_addr = inet_addr(T2A(sub));
  145.             
  146.                 if (sockAddr.sin_addr.s_addr != INADDR_NONE)
  147.                 {
  148.                     sub = inet_ntoa(sockAddr.sin_addr);
  149.                     std::list<CString>::iterator iter;
  150.                     for (iter = ipBindList.begin(); iter != ipBindList.end(); iter++)
  151.                         if (*iter == sub)
  152.                             break;
  153.                     if (iter == ipBindList.end())
  154.                         ipBindList.push_back(sub);
  155.                 }
  156.                 sub = _T("");
  157.             }
  158.         }
  159.         else
  160.             sub += cur;
  161.     }
  162.     if (sub != _T(""))
  163.     {
  164.         //Parse IP
  165.         SOCKADDR_IN sockAddr;
  166.         memset(&sockAddr, 0, sizeof(sockAddr));
  167.         
  168.         sockAddr.sin_family = AF_INET;
  169.         sockAddr.sin_addr.s_addr = inet_addr(T2A(sub));
  170.         
  171.         if (sockAddr.sin_addr.s_addr != INADDR_NONE)
  172.         {
  173.             sub = inet_ntoa(sockAddr.sin_addr);
  174.             std::list<CString>::iterator iter;
  175.             for (iter = ipBindList.begin(); iter != ipBindList.end(); iter++)
  176.                 if (*iter==sub)
  177.                     break;
  178.             if (iter == ipBindList.end())
  179.                 ipBindList.push_back(sub);
  180.         }
  181.         sub = _T("");
  182.     }
  183.     bindIPs = _T("");
  184.     for (std::list<CString>::iterator iter = ipBindList.begin(); iter!=ipBindList.end(); iter++)
  185.         if (*iter != _T("127.0.0.1"))
  186.             bindIPs += *iter + _T(" ");
  187.  
  188.     bindIPs.TrimRight(_T(" "));
  189.     m_IpBindingsResult = bindIPs;
  190.  
  191.     if (!ParseIPFilter(m_IpAddresses))
  192.     {
  193.         GetDlgItem(IDC_OPTIONS_ADMININTERFACE_IPADDRESSES)->SetFocus();
  194.         AfxMessageBox(_T("Invalid IP address/range/mask"));
  195.         return FALSE;
  196.     }
  197.  
  198.     if (m_bChangePass)
  199.     {
  200.         if (m_NewPass == _T("") && m_NewPass2 == _T(""))
  201.             return TRUE;
  202.         if (m_NewPass.GetLength() < 6)
  203.         {
  204.             m_pOptionsDlg->ShowPage(this);
  205.             GetDlgItem(IDC_OPTIONS_ADMININTERFACE_NEWPASS)->SetFocus();
  206.             AfxMessageBox(_T("The admin password has to be at least 6 characters long,"));
  207.             return FALSE;
  208.         }
  209.         if (m_NewPass != m_NewPass2)
  210.         {
  211.             m_pOptionsDlg->ShowPage(this);
  212.             GetDlgItem(IDC_OPTIONS_ADMININTERFACE_NEWPASS)->SetFocus();
  213.             AfxMessageBox(_T("Admin passwords do not match."));
  214.             return FALSE;
  215.         }
  216.     }
  217.     return TRUE;
  218. }
  219.  
  220. void COptionsAdminInterfacePage::SaveData()
  221. {
  222.     m_pOptionsDlg->SetOption(OPTION_ADMINPORT, _ttoi(m_Port));
  223.     m_pOptionsDlg->SetOption(OPTION_ADMINIPBINDINGS, m_IpBindingsResult);
  224.     m_pOptionsDlg->SetOption(OPTION_ADMINIPADDRESSES, m_IpAddresses);
  225.     if (m_bChangePass)
  226.         m_pOptionsDlg->SetOption(OPTION_ADMINPASS, m_NewPass);
  227.     else
  228.         m_pOptionsDlg->SetOption(OPTION_ADMINPASS, _T("*"));
  229. }
  230.  
  231. void COptionsAdminInterfacePage::LoadData()
  232. {
  233.     m_Port.Format(_T("%d"), static_cast<int>(m_pOptionsDlg->GetOptionVal(OPTION_ADMINPORT)));
  234.     m_IpBindings = m_pOptionsDlg->GetOption(OPTION_ADMINIPBINDINGS);
  235.     m_IpAddresses = m_pOptionsDlg->GetOption(OPTION_ADMINIPADDRESSES);
  236.     m_NewPass = m_pOptionsDlg->GetOption(OPTION_ADMINPASS);
  237. }
  238.